home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / CreditNow! / CreditNow! Source / $Utilities / TextField.h < prev   
Encoding:
C/C++ Source or Header  |  1995-04-30  |  4.6 KB  |  173 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        TextField.h
  3.  
  4.     Contains:    TextEdit class to contain TextEdit from Toolbox
  5.                 
  6.  
  7.     Written by:    Andrew Taylor
  8.  
  9.     Theory of Operation:
  10.         Quick and dirty wrapper for TextEdit
  11.         
  12.     Modified from Jens Alfke's FacetList
  13.         This is a quick-n-dirty linked list of TextFields. To use it, create a
  14.         TextFieldList and use the Add and Remove methods to add/remove TextFields.
  15.         To iterate over all the TextFields, do something like this:
  16.         
  17.             for ( TextFieldLink *fl = fieldList.First(); fl->GetTextField(); fl = fl->Next() )
  18.                 DoSomethingWithTextField( fl->GetTextField() );
  19.  
  20.     Copyright:    © 1995 by Appropriate Solutions, Inc., all rights reserved.
  21.  
  22.     Change History (most recent first):
  23.  
  24.  
  25.          <0>    started
  26. */
  27.  
  28. #ifndef _TEXTFIELD_
  29. #define _TEXTFIELD_
  30.  
  31. #include <TextEdit.h>
  32.  
  33.  
  34. #define chTab        0x09
  35. #define chEnter        0x03
  36. #define chReturn    0x0d
  37.  
  38.  
  39. //========================================================================================
  40. // TextField
  41. //========================================================================================
  42.  
  43. class TextField
  44. {
  45. public:
  46.     
  47.             TextField();
  48.             ~TextField();
  49.     void    InitTextField(ODTypeToken id, short maxChars, Rect *destRect);
  50.                 // id identifies what this field is used for
  51.                 // destRect, viewRect are passed to TENew.
  52.                 // maxChars is the maximum characters allowed in the field
  53.     void    ReleaseTextField();
  54.                 // dispose of TextEdit record
  55.                 
  56.     ODTypeToken    GetID()                                {return fIdentifier;}
  57.                 // returns field identifier
  58.             
  59.     Boolean    KeyStroke(char inKey, short modifiers);
  60.                 // enter keystroke into TE record
  61.                 // returns true if keystroke accepted
  62.     Boolean ContainsPoint(Point where);
  63.                 // Determines if point is contained within the view rect.
  64.     void    MouseClick(Point where, EventRecord *event);
  65.                 // pass mouse click to TextEdit
  66.     void    Draw(RgnHandle invalRgn);
  67.                 // draw frame, update TextEdit display
  68.             
  69.     Handle    GetTextHandle(long *usedLength);
  70.                 // returns TextEdit record text handle
  71.     Handle    GetSelectedPtr(Ptr *data, long *length);
  72.                 // set ptr to selected text. Set length of selected text.
  73.                 // caller is expected to lock and unlock handle if use of ptr
  74.                 // will cause memory move.
  75.     void    SetSelection(long start, long end);
  76.         // set the selection range
  77.     void    GetText(Str255 str);
  78.                 // retrieve text from TextEdit record
  79.     void    SetText(Str255 str);
  80.                 // load TextEdit record with text
  81.     Boolean    Validate();
  82.                 // return true if contents valid, false otherwise
  83.                 // should be called when field keyboard focus is being removed
  84.                 // displays reason for failure to user.
  85.             
  86.     void    Activate();
  87.                 // make this the active TE record
  88.     void    Deactivate();
  89.                 // deactivate TE record
  90.     void    Idle();
  91.                 // do some idle time.
  92.             
  93.     void    Cut();
  94.     void    Copy();
  95.     void    Paste();
  96.     void    Clear();
  97.     Boolean    HaveSelection();
  98.     
  99. protected:
  100.     ODTypeToken    fIdentifier;
  101.     TEHandle    fTheTE;
  102.     short        fMaxChars;
  103.     short        fAnchorPoint;
  104. };
  105.  
  106.  
  107. //========================================================================================
  108. // LabeledTextField
  109. //========================================================================================
  110.  
  111. class LabeledTextField : public TextField
  112. {
  113. public:
  114.     
  115.             LabeledTextField();
  116.             ~LabeledTextField();
  117.     void    InitTextField(ODTypeToken id, short maxChars, short lblWidth, Rect *destRect, Str255 label);
  118.                 // id identifies what this field is used for
  119.                 // label is a string displayed to the left of the field
  120.                 // destRect is passed to TENew.
  121.                 // maxChars is the maximum characters allowed in the field
  122.     void    Draw(RgnHandle invalRgn);
  123.     
  124. protected:
  125.     Str255    fLabel;
  126.     Rect    fRect;
  127. };
  128.  
  129.  
  130. //========================================================================================
  131. // TextFieldLink
  132. //========================================================================================
  133.  
  134. class TextFieldLink
  135. {
  136. public:
  137.     
  138.     TextField*    GetTextField( )                {return fTextField;}
  139.     TextFieldLink*    Next( )                    {return fNext;}
  140.     TextFieldLink*    Previous( )                {return fPrev;}
  141.     
  142. protected:
  143.                 TextFieldLink( TextField*, TextFieldLink *list );
  144.                 TextFieldLink( );
  145.                 ~TextFieldLink( );
  146.                 
  147.     TextField        *fTextField;
  148.     TextFieldLink    *fPrev,
  149.                     *fNext;
  150.  
  151.     friend class TextFieldList;
  152. };
  153.  
  154.  
  155. //========================================================================================
  156. // TextFieldList
  157. //========================================================================================
  158.  
  159. class TextFieldList : public TextFieldLink
  160. {
  161. public:
  162.                 TextFieldList( );
  163.                 ~TextFieldList( );
  164.     void        Add( TextField* );
  165.     void        Add(ODTypeToken id, short maxChars, Rect *destRect);
  166.     void        Add(ODTypeToken id, short maxChars, short lblWidth, Rect *destRect, Str255 label);
  167.     void        Remove( TextField* );
  168.     void        InvalAllTextFields( );
  169.     TextFieldLink*    First( )                    {return fNext;}
  170. };
  171.  
  172.  
  173. #endif